package oj;

import java.util.Scanner;

/**
 * @author 郝文雪
 * @date 2022/7/17 22:15
 * @Description Test
 */
public class Day19查找两个字符串a和b的最长公共子串 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            String s1=sc.nextLine();
            String s2=sc.nextLine();
            if(s1.length()>s2.length()){
                String tmp=s1;
                s1=s2;
                s2=tmp;
            }
            int[][] dp=new int[s1.length()+1][s2.length()+1];
            int max=1;
            int maxIdx=0;
            for(int i=1;i<s1.length();i++){
                for(int j=1;j<s2.length();j++){
                    if(s1.charAt(i-1)==s2.charAt(j-1)){
                        dp[i][j]=dp[i-1][j-1]+1;
                    }
                    if(dp[i][j]>max){
                        max=dp[i][j];
                        maxIdx=i;
                    }
                }
            }
            System.out.println(s1.substring(maxIdx-max,maxIdx));
        }
    }
}
